package com.huawei.codearts.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.huawei.codearts.model.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;

import java.math.BigDecimal;
import java.util.List;

/**
 * mybatis 需要用到的 mapper 类
 */

@Mapper
public interface UserMapper extends BaseMapper<User> {
    List<User> getAllUsers();
    User getUserById(Long id);
    // XML方式 mapper 新增数据
    Long insertUser(User user);
    Long updateUser(User user);
    Long deleteUser(Long id);

    // 注解方式 mapper 新增数据
    @Insert("INSERT INTO qhdzs_users(user, name, createTime) VALUES(#{user}, #{name}, #{createTime})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    Long insertUserAnnotation(User user);

    // 注解方式 mapper
    @Insert("update qhdzs_users set score = score - #{score} where id = #{id}")
    Long updateWithTx(BigDecimal score, Long id);
    @Insert("update qhdzs_users set score = score + #{score} where id = #{id}")
    Long updateWithTx2(BigDecimal score, Long id);
}


